% Generator: GNU source-highlight, by Lorenzo Bettini, http://www.gnu.org/software/src-highlite
{\ttfamily \raggedright {
\noindent
\mbox{}\textcolor{ForestGreen}{int}\ n\textcolor{BrickRed}{,}\ m\textcolor{BrickRed}{;} \\
\mbox{}cin\ \textcolor{BrickRed}{$>$$>$}\ n\ \textcolor{BrickRed}{$>$$>$}\ m\textcolor{BrickRed}{;} \\
\mbox{}vector\ \textcolor{BrickRed}{$<$}\ \textcolor{TealBlue}{vector$<$char$>$\ $>$}\ \textbf{\textcolor{Black}{a}}\ \textcolor{BrickRed}{(}n\textcolor{BrickRed}{,}\ vector\textcolor{BrickRed}{$<$}\textcolor{ForestGreen}{char}\textcolor{BrickRed}{$>$}\ \textcolor{BrickRed}{(}m\textcolor{BrickRed}{));} \\
\mbox{}\textbf{\textcolor{Blue}{for}}\ \textcolor{BrickRed}{(}\textcolor{ForestGreen}{int}\ i\textcolor{BrickRed}{=}\textcolor{Purple}{0}\textcolor{BrickRed}{;}\ i\textcolor{BrickRed}{$<$}n\textcolor{BrickRed}{;}\ \textcolor{BrickRed}{++}i\textcolor{BrickRed}{)} \\
\mbox{}\ \ \textbf{\textcolor{Blue}{for}}\ \textcolor{BrickRed}{(}\textcolor{ForestGreen}{int}\ j\textcolor{BrickRed}{=}\textcolor{Purple}{0}\textcolor{BrickRed}{;}\ j\textcolor{BrickRed}{$<$}m\textcolor{BrickRed}{;}\ \textcolor{BrickRed}{++}j\textcolor{BrickRed}{)} \\
\mbox{}\ \ \ \ cin\ \textcolor{BrickRed}{$>$$>$}\ a\textcolor{BrickRed}{[}i\textcolor{BrickRed}{][}j\textcolor{BrickRed}{];} \\
\mbox{} \\
\mbox{}\textcolor{ForestGreen}{int}\ ans\ \textcolor{BrickRed}{=}\ \textcolor{Purple}{0}\textcolor{BrickRed}{;} \\
\mbox{}\textcolor{TealBlue}{vector$<$int$>$}\ \textbf{\textcolor{Black}{d}}\ \textcolor{BrickRed}{(}m\textcolor{BrickRed}{,}\ \textcolor{BrickRed}{-}\textcolor{Purple}{1}\textcolor{BrickRed}{);} \\
\mbox{}\textcolor{TealBlue}{vector$<$int$>$}\ \textbf{\textcolor{Black}{dl}}\ \textcolor{BrickRed}{(}m\textcolor{BrickRed}{),}\ \textbf{\textcolor{Black}{dr}}\ \textcolor{BrickRed}{(}m\textcolor{BrickRed}{);} \\
\mbox{}\textcolor{TealBlue}{stack$<$int$>$}\ st\textcolor{BrickRed}{;} \\
\mbox{}\textbf{\textcolor{Blue}{for}}\ \textcolor{BrickRed}{(}\textcolor{ForestGreen}{int}\ i\textcolor{BrickRed}{=}\textcolor{Purple}{0}\textcolor{BrickRed}{;}\ i\textcolor{BrickRed}{$<$}n\textcolor{BrickRed}{;}\ \textcolor{BrickRed}{++}i\textcolor{BrickRed}{)}\ \textcolor{Red}{\{} \\
\mbox{}\ \ \textbf{\textcolor{Blue}{for}}\ \textcolor{BrickRed}{(}\textcolor{ForestGreen}{int}\ j\textcolor{BrickRed}{=}\textcolor{Purple}{0}\textcolor{BrickRed}{;}\ j\textcolor{BrickRed}{$<$}m\textcolor{BrickRed}{;}\ \textcolor{BrickRed}{++}j\textcolor{BrickRed}{)} \\
\mbox{}\ \ \ \ \textbf{\textcolor{Blue}{if}}\ \textcolor{BrickRed}{(}a\textcolor{BrickRed}{[}i\textcolor{BrickRed}{][}j\textcolor{BrickRed}{]}\ \textcolor{BrickRed}{==}\ \textcolor{Purple}{1}\textcolor{BrickRed}{)} \\
\mbox{}\ \ \ \ \ \ d\textcolor{BrickRed}{[}j\textcolor{BrickRed}{]}\ \textcolor{BrickRed}{=}\ i\textcolor{BrickRed}{;} \\
\mbox{}\ \ \textbf{\textcolor{Blue}{while}}\ \textcolor{BrickRed}{(!}st\textcolor{BrickRed}{.}\textbf{\textcolor{Black}{empty}}\textcolor{BrickRed}{())}\ st\textcolor{BrickRed}{.}\textbf{\textcolor{Black}{pop}}\textcolor{BrickRed}{();} \\
\mbox{}\ \ \textbf{\textcolor{Blue}{for}}\ \textcolor{BrickRed}{(}\textcolor{ForestGreen}{int}\ j\textcolor{BrickRed}{=}\textcolor{Purple}{0}\textcolor{BrickRed}{;}\ j\textcolor{BrickRed}{$<$}m\textcolor{BrickRed}{;}\ \textcolor{BrickRed}{++}j\textcolor{BrickRed}{)}\ \textcolor{Red}{\{} \\
\mbox{}\ \ \ \ \textbf{\textcolor{Blue}{while}}\ \textcolor{BrickRed}{(!}st\textcolor{BrickRed}{.}\textbf{\textcolor{Black}{empty}}\textcolor{BrickRed}{()}\ \textcolor{BrickRed}{\&\&}\ d\textcolor{BrickRed}{[}st\textcolor{BrickRed}{.}\textbf{\textcolor{Black}{top}}\textcolor{BrickRed}{()]}\ \textcolor{BrickRed}{$<$=}\ d\textcolor{BrickRed}{[}j\textcolor{BrickRed}{])}\ \ st\textcolor{BrickRed}{.}\textbf{\textcolor{Black}{pop}}\textcolor{BrickRed}{();} \\
\mbox{}\ \ \ \ dl\textcolor{BrickRed}{[}j\textcolor{BrickRed}{]}\ \textcolor{BrickRed}{=}\ st\textcolor{BrickRed}{.}\textbf{\textcolor{Black}{empty}}\textcolor{BrickRed}{()}\ \textcolor{BrickRed}{?}\ \textcolor{BrickRed}{-}\textcolor{Purple}{1}\ \textcolor{BrickRed}{:}\ st\textcolor{BrickRed}{.}\textbf{\textcolor{Black}{top}}\textcolor{BrickRed}{();} \\
\mbox{}\ \ \ \ st\textcolor{BrickRed}{.}\textbf{\textcolor{Black}{push}}\ \textcolor{BrickRed}{(}j\textcolor{BrickRed}{);} \\
\mbox{}\ \ \textcolor{Red}{\}} \\
\mbox{}\ \ \textbf{\textcolor{Blue}{while}}\ \textcolor{BrickRed}{(!}st\textcolor{BrickRed}{.}\textbf{\textcolor{Black}{empty}}\textcolor{BrickRed}{())}\ st\textcolor{BrickRed}{.}\textbf{\textcolor{Black}{pop}}\textcolor{BrickRed}{();} \\
\mbox{}\ \ \textbf{\textcolor{Blue}{for}}\ \textcolor{BrickRed}{(}\textcolor{ForestGreen}{int}\ j\textcolor{BrickRed}{=}m\textcolor{BrickRed}{-}\textcolor{Purple}{1}\textcolor{BrickRed}{;}\ j\textcolor{BrickRed}{$>$=}\textcolor{Purple}{0}\textcolor{BrickRed}{;}\ \textcolor{BrickRed}{-\/-}j\textcolor{BrickRed}{)}\ \textcolor{Red}{\{} \\
\mbox{}\ \ \ \ \textbf{\textcolor{Blue}{while}}\ \textcolor{BrickRed}{(!}st\textcolor{BrickRed}{.}\textbf{\textcolor{Black}{empty}}\textcolor{BrickRed}{()}\ \textcolor{BrickRed}{\&\&}\ d\textcolor{BrickRed}{[}st\textcolor{BrickRed}{.}\textbf{\textcolor{Black}{top}}\textcolor{BrickRed}{()]}\ \textcolor{BrickRed}{$<$=}\ d\textcolor{BrickRed}{[}j\textcolor{BrickRed}{])}\ \ st\textcolor{BrickRed}{.}\textbf{\textcolor{Black}{pop}}\textcolor{BrickRed}{();} \\
\mbox{}\ \ \ \ dr\textcolor{BrickRed}{[}j\textcolor{BrickRed}{]}\ \textcolor{BrickRed}{=}\ st\textcolor{BrickRed}{.}\textbf{\textcolor{Black}{empty}}\textcolor{BrickRed}{()}\ \textcolor{BrickRed}{?}\ m\ \textcolor{BrickRed}{:}\ st\textcolor{BrickRed}{.}\textbf{\textcolor{Black}{top}}\textcolor{BrickRed}{();} \\
\mbox{}\ \ \ \ st\textcolor{BrickRed}{.}\textbf{\textcolor{Black}{push}}\ \textcolor{BrickRed}{(}j\textcolor{BrickRed}{);} \\
\mbox{}\ \ \textcolor{Red}{\}} \\
\mbox{}\ \ \textbf{\textcolor{Blue}{for}}\ \textcolor{BrickRed}{(}\textcolor{ForestGreen}{int}\ j\textcolor{BrickRed}{=}\textcolor{Purple}{0}\textcolor{BrickRed}{;}\ j\textcolor{BrickRed}{$<$}m\textcolor{BrickRed}{;}\ \textcolor{BrickRed}{++}j\textcolor{BrickRed}{)} \\
\mbox{}\ \ \ \ ans\ \textcolor{BrickRed}{=}\ \textbf{\textcolor{Black}{max}}\ \textcolor{BrickRed}{(}ans\textcolor{BrickRed}{,}\ \textcolor{BrickRed}{(}i\ \textcolor{BrickRed}{-}\ d\textcolor{BrickRed}{[}j\textcolor{BrickRed}{])}\ \textcolor{BrickRed}{*}\ \textcolor{BrickRed}{(}dr\textcolor{BrickRed}{[}j\textcolor{BrickRed}{]}\ \textcolor{BrickRed}{-}\ dl\textcolor{BrickRed}{[}j\textcolor{BrickRed}{]}\ \textcolor{BrickRed}{-}\ \textcolor{Purple}{1}\textcolor{BrickRed}{));} \\
\mbox{}\textcolor{Red}{\}} \\
\mbox{} \\
\mbox{}cout\ \textcolor{BrickRed}{$<$$<$}\ ans\textcolor{BrickRed}{;}
}